package cn.ewan.cloud.tenant.data.router.example.controller;

import cn.ewan.cloud.common.web.support.rocketmq.RocketMQMsg;
import cn.ewan.cloud.tenant.data.router.example.mapper.AppInfo;
import cn.ewan.cloud.tenant.data.router.example.mapper.AppInfoMapper;
import cn.ewan.cloud.tenant.data.router.example.mapper.GovUserEwanA;
import cn.ewan.cloud.tenant.data.router.example.mapper.GovUserEwanAMapper;
import cn.ewan.cloud.tenant.data.router.mq.core.TenantRocketMQProducer;
import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.client.producer.SendResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author lgh
 * @date 2022/12/13 18:12
 */
@RestController
public class TestController {

    @Resource
    AppInfoMapper appInfoMapper;

    @Resource
    GovUserEwanAMapper govUserEwanAMapper;

    @Resource
    TenantRocketMQProducer tenantRocketMQProducer;


    public static final String topic="TENANT_TEST_TOPIC";


    @GetMapping("sendMq")
    public String sendMq(String content) {
        SendResult sendResult = tenantRocketMQProducer.syncSend(new RocketMQMsg(topic, content));
        return JSONObject.toJSONString(sendResult);
    }


    @GetMapping("find/appname")
    public String getApp(Integer appId) {
        AppInfo appInfo = appInfoMapper.selectById(appId);
        return appInfo == null ? "应用不存在" : appInfo.getAppName();
    }


    @GetMapping("find/tenant/appname")
    public String getTenantApp(Integer appId) {
        String app = getApp(appId);
        return app;
    }


    @GetMapping("find/tenant/govUserEwanA")
    public String govUserEwanA(Integer id) {
        GovUserEwanA govUserEwanA = govUserEwanAMapper.selectById(id);
        if (govUserEwanA == null) {
            return "找不到记录";
        }
        return "id=" + id + ",pi=" + govUserEwanA.getGovPi() + ",openId=" + govUserEwanA.getPOpenId() + ",name=" + govUserEwanA.getRealName();
    }
}
